import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
    {
        path: '/',
        redirect: '/index',
    },
    {
        path: '/index',
        name: 'index',
        meta: {
            title: '首页',
        },
        component: () => import('@/views/index.vue'),
    },
    {
        path: '/login',
        name: 'Login',
        meta: {
            title: '登录',
            hasView:false,
        },
        component: () => import('@/views/login.vue'),
    },
    {
        path: '/singin',
        name: 'Singin',
        meta: {
            title: '注册',
            hasView:false,
        },
        component: () => import('@/views/singin.vue'),
    },
    {
        path: '/renewpwd',
        name: 'renewpwd',
        meta: {
            title: '重置密码',
            hasView:false,
        },
        component: () => import('@/views/renewpwd.vue'),
    },
    {
        path: '/test',
        name: 'test',
        meta: {
            title: '测试页',
        },
        component: () => import('@/views/test.vue'),
    },
    {
        path: '/product',
        name: 'product',
        meta: {
            title: '商品详情',
        },
        component: () => import('@/views/product/index.vue'),
    },
    {
        path: '/search',
        name: 'search',
        meta: {
            title: '搜索详情页',
        },
        component: () => import('@/views/search/index.vue'),
    },
    {
        path: '/chat',
        name: 'chat',
        meta: {
            title: '搜索详情页',
        },
        component: () => import('@/views/chat/index.vue'),
    },
    {
        path: '/test-form',
        name: 'test-form',
        meta: {
            title: '搜索详情页2',
        },
        component: () => import('@/components/test-form.vue'),
    },
    // {
    //     path: '/loding',
    //     name: 'loding',
    //     meta: {
    //         title: '搜索栏',
    //     },
    //     component: () => import('@/components/loding.vue'),
    // },
    {
        // 404路由
        // /:catchAll(.*) 匹配任意路径
        // 当前面所有的路由都匹配失败
        // 就会被当前路由捕获
        path: '/:catchAll(.*)',
        meta: { title: '404' },
        component: () => import('@/views/404.vue'),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title + ' - 辰星生物';
    }
    next();
});
export default router;
